<?php
require_once '../conf.php';

class postsFromWpToPg{
	
	private $db; 
	
	function __construct(){
		try{
		
			$pdo = new PDO('mysql:host='.MYSQL_WP_DB_HOST.';dbname='.MYSQL_WP_DB_NAME, MYSQL_WP_DB_USER, MYSQL_WP_DB_PASS,
			array(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) );
			$pdo->query('Set names utf8');
			//Pobranie wszystkich artykułów
			$articlesMany= $pdo->query("
					SELECT *
						FROM `wp_posts`
						WHERE post_status = 'publish'
						ORDER BY post_date DESC
			");
			
			$this->db = pg_connect("host='".DB_HOST."' dbname='".DB_NAME."' user='".DB_USER."' password='".DB_PASS."'");
			

			
			$tablica; //Tablica z meta_value pochodzacymi od short_opis
			$i=0;
				
			foreach ($articlesMany as $article){
				
	
				$x = strpos($article['post_content'], ".",300);
				$krotkiOpis = substr($article['post_content'],0,$x); 
				
				
				
				
				$query = "
													INSERT INTO articles(
								             			article, url, post_date,title,introduction)
								    					VALUES ( '".$article['post_content']."', '".$article['post_name']."', '".$article['post_date']."','".$article['post_title']."','".$krotkiOpis."');
												
												";
				
							$result = pg_query($this->db,$query);
				
				//print_r($article);
			}
					}catch (Exception $e){
						echo $e->getMessage();
					}		
		
	}
}

$test = new postsFromWpToPg();
?>